package Rangel.common.world.helper;

import javolution.util.FastMap;
import rescuecore2.standard.entities.StandardEntity;
import rescuecore2.worldmodel.Property;

import java.util.Map;


public class PropertyHelper implements IHelper {//属性

    protected RangelWorldHelper world;
    protected Map<Property, Integer> propertyTimeMap = new FastMap<>();

    public PropertyHelper(RangelWorldHelper world) {
        this.world = world;
    }

    public void init() {
        propertyTimeMap.clear();
    }

    public void update() {

    }

    public int getEntityLastUpdateTime(StandardEntity entity) {//获取实体的最后更新时间
        int maxTime = Integer.MIN_VALUE;
        for (Property property : entity.getProperties()) {
            Integer value = getPropertyTime(property);
            if (value > maxTime) {
                maxTime = value;
            }
        }

        return maxTime;
    }

    public Integer getPropertyTime(Property property) {//获取时间属性
        Integer integer = propertyTimeMap.get(property);
        if (integer == null) {
            return 0;
        }
        return integer;
    }

    public void setPropertyTime(Property property, Integer time) {
        propertyTimeMap.put(property, time);
    }//设置时间属性

    public void addEntityProperty(StandardEntity entity, int time) {//添加实体属性
        for (Property property : entity.getProperties()) {
            propertyTimeMap.put(property, time);
        }
    }
}
